// pages/component/carddepots/getcarddetail/getcarddetail.js
var GlobalData = require('../../../../utils/GlobalData.js');
var dataManager = require('../../../../utils/dataManager.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detailData: [],
    str: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.removeBtnObserver("getcarddetail")
    if (GlobalData.GetCardDetail) {
      this.onComplete();
    } else {
      dataManager.rigisterObserver("getcarddetail", this.onComplete, this);
      dataManager.getGetCardDetail();
    }
  },
  onComplete: function () {

    var detail = GlobalData.clone(GlobalData.GetCardDetail);
    detail["createtime"] = detail["createtime"].replace('T', ' ');

    for (let i = 0; i < detail.cdklist.length; i++) {
      if (detail.cdklist[i].state == "已使用") {
        detail.cdklist[i].picture = "down";
      }
      else {
        detail.cdklist[i].picture = "fasong";
      }
    }

    this.setData({
      detailData: detail
    })
    //清空购卡记录
    GlobalData.BuyCardRecord.splice(0, GlobalData.BuyCardRecord.length);
    GlobalData.BuyCardRecordother["index"] = 1

  },
  showDetail: function (e) {
    let that = this
    that.setData({
      str: e.currentTarget.dataset.id.cdkey
    })
    // let str = e.currentTarget.dataset.id.cdkey
    if (e.currentTarget.dataset.id.state == "未使用") {
      wx.setClipboardData({
        data: that.data.str,
        success() {
          wx.getClipboardData({
            success(res) {
              app.show("已复制成功。")

            }
          })
        },
        fail(res) {
          console.error(res)
        }
      })
    } else {

    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})